package flyweightPattern;

import java.util.HashMap;
import java.util.Map;

//享元工厂
public class GoodsFactory {

    private static Map<String, Goods> poolMap = new HashMap<>();

    public static Goods getGoods(String name) {
        if (poolMap.containsKey(name)) {
            //输入sout，按下enter键，生成System.out.println()方法.
            System.out.println("Use Cache Key : " + name);
            return poolMap.get(name);
        } else {
            Goods goods = new Goods(name);
            poolMap.put(name, goods);
            System.out.println("Create Goods Key : " + name);
            return goods;
        }
    }

}
